package com.yq.day30.udp1.v4;

import com.yq.utils.NetUtils;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @author 3307235355@qq.com
 * @description
 * @since 2022/06/30 17:39
 */
public class ReceiveTask implements Runnable {
    DatagramSocket socket;
    public ReceiveTask(DatagramSocket socket) {
        this.socket = socket;
    }
    @Override
    public void run() {
        //只接受
        while (true){
            DatagramPacket receivePacket = NetUtils.getReceivePacket();
            try {
                socket.receive(receivePacket);
                String parse = NetUtils.parse(receivePacket);
                System.out.println(parse);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
